package org.jeecg.modules.sssj.controller;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.config.annotations.OrgPermissionAnnotation;
import org.jeecg.config.util.CurrentOrgInfoUtil;
import org.jeecg.modules.basesource.constant.CwbbKjzzEnum;
import org.jeecg.modules.basesource.entity.SbCwbbBw;
import org.jeecg.modules.basesource.service.ISbCwbbBwService;
import org.jeecg.modules.basesource.utils.cwbb.CwbbUtil;
import org.jeecg.modules.dzswj.vo.response.cwbb.*;
import org.jeecg.modules.fk.entity.DjOrg;
import org.jeecg.modules.fk.service.IDjOrgService;
import org.jeecg.modules.sssj.dto.CwbbDto;
import org.jeecg.modules.sssj.dto.MaxSsqDto;
import org.jeecg.modules.sssj.view.MyJeecgTemplateExcelView;
import org.jeecg.modules.sssj.vo.CwbbSssjVo;
import org.jeecg.modules.sssj.vo.ExportXlsErrorVo;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.def.TemplateExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.net.URL;
import java.util.*;

/**
 * @author chensherun on 2022/6/20.
 * @version 1.0
 */
@Api(tags="实时数据-财务报表")
@RestController
@RequestMapping("/sssj/sssjCwbb")
public class SssjCwbbController {

    @Autowired
    private ISbCwbbBwService sbCwbbBwService;
    @Autowired
    private IDjOrgService djOrgService;

    @Value("${sssj.cwbb.excelTemplateDir}")
    private String excelTemplateDir;

    @ApiOperation(value = "查询纳税人最大属期的财报")
    @OrgPermissionAnnotation
    @PostMapping(value = "/getNsrMaxSsq")
    public Result<String> getNsrMaxSsq(@Validated @RequestBody MaxSsqDto maxSsqDto) {
        String tynsrsbh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        String maxSsqq = sbCwbbBwService.getMaxJbSsqByNsr(tynsrsbh);
        return Result.OK(maxSsqq);
    }

    @ApiOperation(value = "查询纳税人最大属期的财报(年报)")
    @OrgPermissionAnnotation
    @PostMapping(value = "/getNsrMaxNbSsq")
    public Result<String> getNsrMaxNbSsq(@Validated @RequestBody MaxSsqDto maxSsqDto) {
        String tynsrsbh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        String maxSsqq = sbCwbbBwService.getMaxNbSsqByNsr(tynsrsbh);
        return Result.OK(maxSsqq);
    }

    @ApiOperation(value = "查询财报实时数据")
    @OrgPermissionAnnotation
    @PostMapping(value = "/getCwbb")
    public Result<CwbbSssjVo> getCwbbData(@Validated @RequestBody CwbbDto cwbbDto) {
        String tynsrsbh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        CwbbSssjVo cwbbSssj = sbCwbbBwService.getCwbbSssj(tynsrsbh, cwbbDto.getSkssqq(), cwbbDto.getSkssqz());
        return Result.OK(cwbbSssj);
    }

    @RequiresPermissions("realTimeData:finance:export")
    @OrgPermissionAnnotation
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, @Validated CwbbDto cwbbDto) {
        String tynsrsbh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        SbCwbbBw cwbbBw = sbCwbbBwService.getByCompositePk(tynsrsbh, cwbbDto.getSkssqq(), cwbbDto.getSkssqz());
        if (cwbbBw == null) {
//            throw new JeecgBootException("本期财报不存在");
            return exportError(tynsrsbh,"本期财报不存在");
        }
        GsCwbbVo gsCwbbVo = JSONObject.parseObject(cwbbBw.getJsonBw(), new TypeReference<GsCwbbVo>() {});
        DjOrg djOrg = djOrgService.getByNsrsbhOrShxydm(tynsrsbh);
        JSONObject data = new JSONObject();
        data.put("tynsrsbh", StringUtils.isNotBlank(djOrg.getShxydm()) ? djOrg.getShxydm() : djOrg.getNsrsbh());
        data.put("nsrmc", djOrg.getNsrmc());
        CwbbKjzzEnum kjzz = CwbbUtil.checkKjzz(gsCwbbVo);
        Map<String, Object> zcfzb = new HashMap<>();
        Map<String, Object> lrb = new HashMap<>();
        Map<String, Object> xjllb = new HashMap<>();
        data.put("lrb", lrb);
        data.put("xjllb", xjllb);
        data.put("zcfzb", zcfzb);
        xjllb.put("list", new ArrayList<>());
        lrb.put("list", new ArrayList<>());
        zcfzb.put("list", new ArrayList<>());
        String templateFile = null;
        //判断年报还是季度
        boolean isYear = false;
        String templateFileTtype = "";
        if (cwbbDto.getSkssqq().endsWith("01-01") && cwbbDto.getSkssqz().endsWith("12-31")) {
            isYear = true;
            templateFileTtype = "_nb";
        }

        if (CwbbKjzzEnum.QYKJZZ_YBQY == kjzz) {
             templateFile = "cwbb_qykjzz_ybqy_template" + templateFileTtype + ".xls";
            //利润表实体封装
            if (gsCwbbVo.getYbqylrbVO() != null
                    && gsCwbbVo.getYbqylrbVO().getYbqylrbGrid() != null
                    && gsCwbbVo.getYbqylrbVO().getYbqylrbGrid().getYbqylrbGridlb() != null) {
                List<YbqylrbGridlb> lrbList = gsCwbbVo.getYbqylrbVO().getYbqylrbGrid().getYbqylrbGridlb();
                lrbList.forEach( e -> {
                    if (StringUtils.isNotBlank(e.getHmc())) {
                        e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                    }
                });
                lrb.put("list", lrbList);
                NsrxxForm nsrxxForm = gsCwbbVo.getYbqylrbVO().getNsrxxForm2();
                if (nsrxxForm != null) {
                    lrb.put("bsrq", nsrxxForm.getBsrq());
                }
                lrb.put("ssqq", cwbbDto.getSkssqq());
                lrb.put("ssqz", cwbbDto.getSkssqz());
            }
            //现金流量表
            if (gsCwbbVo.getYbqyxjllbVO() != null
                    && gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid() != null
                    && gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid().getYbqyxjllbGridlb() != null) {
                List<YbqyxjllbGridlb> xjllbList = gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid().getYbqyxjllbGridlb();
                xjllbList.forEach( e -> {
                    if (StringUtils.isNotBlank(e.getHmc())) {
                        e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                    }
                });
                xjllb.put("list", xjllbList);
                NsrxxForm nsrxxForm = gsCwbbVo.getYbqyxjllbVO().getNsrxxForm3();
                if (nsrxxForm != null) {
                    xjllb.put("bsrq", nsrxxForm.getBsrq());
                }
                xjllb.put("ssqq", cwbbDto.getSkssqq());
                xjllb.put("ssqz", cwbbDto.getSkssqz());
            }

            //资产负债表实体封装
            if (gsCwbbVo.getYbqyzcfzbVO() != null
                    && gsCwbbVo.getYbqyzcfzbVO().getYbqyzcfzbzbGrid() != null
                    && gsCwbbVo.getYbqyzcfzbVO().getYbqyzcfzbzbGrid().getYbqyzcfzbzbGridlb() != null) {
                List<YbqyzcfzbzbGridlb> zcfzbList = gsCwbbVo.getYbqyzcfzbVO().getYbqyzcfzbzbGrid().getYbqyzcfzbzbGridlb();
                zcfzbList.forEach( e -> {
                    if (StringUtils.isNotBlank(e.getQyxmmc())) {
                        e.setQyxmmc(e.getQyxmmc().replaceAll((char) (65311) + "", " "));
                    }
                    if (StringUtils.isNotBlank(e.getZcxmmc())) {
                        e.setZcxmmc(e.getZcxmmc().replace((char) (65311) + "", " "));
                    }
                });
                zcfzb.put("list", zcfzbList);
                zcfzb.put("nsrxxForm", gsCwbbVo.getYbqyzcfzbVO().getNsrxxForm1());
                NsrxxForm nsrxxForm = gsCwbbVo.getYbqyzcfzbVO().getNsrxxForm1();
                if (nsrxxForm != null) {
                    zcfzb.put("zcfzbr", nsrxxForm.getZcfzbr());
                }
                zcfzb.put("ssqq", cwbbDto.getSkssqq());
                zcfzb.put("ssqz", cwbbDto.getSkssqz());
            }

        } else if (CwbbKjzzEnum.QYKJZZ_YBQYYZX == kjzz) {
            templateFile = "cwbb_qykjzz_ybqyyzx_template" + templateFileTtype + ".xls";
            //利润表实体封装
            if (gsCwbbVo.getYbqylrbyzxVO() != null
                    && gsCwbbVo.getYbqylrbyzxVO().getYbqylrbyzxGrid() != null
                    && gsCwbbVo.getYbqylrbyzxVO().getYbqylrbyzxGrid().getYbqylrbyzxGridlb() != null) {
                List<YbqylrbyzxGridlb> lrbList = gsCwbbVo.getYbqylrbyzxVO().getYbqylrbyzxGrid().getYbqylrbyzxGridlb();
                lrbList.forEach( e -> {
                    if (StringUtils.isNotBlank(e.getHmc())) {
                        e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                    }
                });
                lrb.put("list", lrbList);
                NsrxxForm nsrxxForm = gsCwbbVo.getYbqylrbyzxVO().getNsrxxForm2();
                if (nsrxxForm != null) {
                    lrb.put("bsrq", nsrxxForm.getBsrq());
                }
                lrb.put("ssqq", cwbbDto.getSkssqq());
                lrb.put("ssqz", cwbbDto.getSkssqz());
            }
            //现金流量表实体封装
            if (gsCwbbVo.getYbqyxjllbVO() != null
                    && gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid() != null
                    && gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid().getYbqyxjllbGridlb() != null) {
                List<YbqyxjllbGridlb> xjllbList = gsCwbbVo.getYbqyxjllbVO().getYbqyxjllbGrid().getYbqyxjllbGridlb();
                xjllbList.forEach( e -> {
                    if (StringUtils.isNotBlank(e.getHmc())) {
                        e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                    }
                });
                xjllb.put("list", xjllbList);
                NsrxxForm nsrxxForm = gsCwbbVo.getYbqyxjllbVO().getNsrxxForm3();
                if (nsrxxForm != null) {
                    xjllb.put("bsrq", nsrxxForm.getBsrq());
                }
                xjllb.put("ssqq", cwbbDto.getSkssqq());
                xjllb.put("ssqz", cwbbDto.getSkssqz());
            }

            //资产负债表实体封装
            if (gsCwbbVo.getYbqyzcfzbyzxVO() != null
                    && gsCwbbVo.getYbqyzcfzbyzxVO().getYbqyzcfzbzbyzxGrid() != null
                    && gsCwbbVo.getYbqyzcfzbyzxVO().getYbqyzcfzbzbyzxGrid().getYbqyzcfzbzbyzxGridlb() != null) {
                List<YbqyzcfzbzbyzxGridlb> zcfzbList = gsCwbbVo.getYbqyzcfzbyzxVO().getYbqyzcfzbzbyzxGrid().getYbqyzcfzbzbyzxGridlb();
                zcfzbList.forEach( e -> {
                    if (StringUtils.isNotBlank(e.getQyxmmc())) {
                        e.setQyxmmc(e.getQyxmmc().replaceAll((char) (65311) + "", " "));
                    }
                    if (StringUtils.isNotBlank(e.getZcxmmc())) {
                        e.setZcxmmc(e.getZcxmmc().replace((char) (65311) + "", " "));
                    }
                });
                zcfzb.put("list", zcfzbList);
                NsrxxForm nsrxxForm = gsCwbbVo.getYbqyzcfzbyzxVO().getNsrxxForm1();
                if (nsrxxForm != null) {
                    zcfzb.put("zcfzbr", nsrxxForm.getZcfzbr());
                }
                zcfzb.put("ssqq", cwbbDto.getSkssqq());
                zcfzb.put("ssqz", cwbbDto.getSkssqz());
            }
        } else if (CwbbKjzzEnum.XQYKJZZ == kjzz) {
            templateFile = "cwbb_xqykjzz_template" + templateFileTtype + ".xls";
            if (isYear == true) {
                if (gsCwbbVo.getXqylrbnb() != null
                        && gsCwbbVo.getXqylrbnb().getSyxqylrbnbGrid() != null
                        && gsCwbbVo.getXqylrbnb().getSyxqylrbnbGrid().getXqylrbnbGridlb() != null) {
                    NsrxxForm nsrxxForm = gsCwbbVo.getXqylrbnb().getNsrxxForm4();
                    List<XqylrbnbGridlb> lrbnbList = gsCwbbVo.getXqylrbnb().getSyxqylrbnbGrid().getXqylrbnbGridlb();
                    lrbnbList.forEach( e -> {
                        if (StringUtils.isNotBlank(e.getHmc())) {
                            e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                        }
                    });
                    lrb.put("list", lrbnbList);
                    if (nsrxxForm != null) {
                        lrb.put("bsrq", nsrxxForm.getBsrq());
                    }
                    lrb.put("ssqq", cwbbDto.getSkssqq());
                    lrb.put("ssqz", cwbbDto.getSkssqz());
                }
                if (gsCwbbVo.getSyxqyxjllbnb() != null
                        && gsCwbbVo.getSyxqyxjllbnb().getXqyxjllbnGrid() != null
                        && gsCwbbVo.getSyxqyxjllbnb().getXqyxjllbnGrid().getXqyxjllbnGridlb() != null) {
                    NsrxxForm nsrxxForm = gsCwbbVo.getSyxqyxjllbnb().getNsrxxForm5();
                    List<XqyxjllbnGridlb> xjllbnbList = gsCwbbVo.getSyxqyxjllbnb().getXqyxjllbnGrid().getXqyxjllbnGridlb();
                    xjllbnbList.forEach( e -> {
                        if (StringUtils.isNotBlank(e.getHmc())) {
                            e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                        }
                    });
                    xjllb.put("list", xjllbnbList);
                    if (nsrxxForm != null) {
                        xjllb.put("bsrq", nsrxxForm.getBsrq());
                    }
                    xjllb.put("ssqq", cwbbDto.getSkssqq());
                    xjllb.put("ssqz", cwbbDto.getSkssqz());
                }
            } else {
                if (gsCwbbVo.getSyxqylrb() != null
                        && gsCwbbVo.getSyxqylrb().getSyxqylrbGrid() != null
                        && gsCwbbVo.getSyxqylrb().getSyxqylrbGrid().getSyxqylrbGridlb() != null) {
                    List<XqylrbnbGridlb> lrbList = gsCwbbVo.getSyxqylrb().getSyxqylrbGrid().getSyxqylrbGridlb();
//                    //对该企业利润表控制台打印
//                    if ("914401013275430824".equals(cwbbBw.getTynsrsbh()) && "2019-04-01".equals(cwbbBw.getSkssqq())) {
//                        lrbList.forEach( e -> {
//                            if (StringUtils.isNotBlank(e.getHmc())) {
//                                System.out.println(e.getHmc());
//                                for (int i = 0; i < e.getHmc().length(); i++) {
//                                    System.out.print(e.getHmc().charAt(i) - 0);
//                                    System.out.print(" ");
//                                    System.out.println();
//                                }
//                            }
//                        });
//                    }
                    lrbList.forEach( e -> {
                        if (StringUtils.isNotBlank(e.getHmc())) {
                            e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                        }
                    });
                    lrb.put("list", lrbList);
                    NsrxxForm nsrxxForm = gsCwbbVo.getSyxqylrb().getNsrxxForm2();
                    if (nsrxxForm != null) {
                        lrb.put("bsrq", nsrxxForm.getBsrq());
                    }
                    lrb.put("ssqq", cwbbDto.getSkssqq());
                    lrb.put("ssqz", cwbbDto.getSkssqz());
                }
                if (gsCwbbVo.getSyxqyxjllb() != null
                        && gsCwbbVo.getSyxqyxjllb().getXqyxjllbGrid() != null
                        && gsCwbbVo.getSyxqyxjllb().getXqyxjllbGrid().getXqyxjllbGridlb() != null) {
                    List<XqyxjllbnGridlb> xjllbList = gsCwbbVo.getSyxqyxjllb().getXqyxjllbGrid().getXqyxjllbGridlb();
                    xjllbList.forEach( e -> {
                        if (StringUtils.isNotBlank(e.getHmc())) {
                            e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                        }
                    });
                    xjllb.put("list", xjllbList);
                    NsrxxForm nsrxxForm = gsCwbbVo.getSyxqyxjllb().getNsrxxForm3();
                    if (nsrxxForm != null) {
                        xjllb.put("bsrq", nsrxxForm.getBsrq());
                    }
                    xjllb.put("ssqq", cwbbDto.getSkssqq());
                    xjllb.put("ssqz", cwbbDto.getSkssqz());
                }
            }
            if (gsCwbbVo.getSyxqyzcfzb() != null
                    && gsCwbbVo.getSyxqyzcfzb().getSyxqyzcfzbGrid() != null
                    && gsCwbbVo.getSyxqyzcfzb().getSyxqyzcfzbGrid().getXqyzcfzbGridlb() != null) {
                List<XqyzcfzbGridlb> zcfzbList = gsCwbbVo.getSyxqyzcfzb().getSyxqyzcfzbGrid().getXqyzcfzbGridlb();
                zcfzbList.forEach( e -> {
                    if (StringUtils.isNotBlank(e.getQyxmmc())) {
                        e.setQyxmmc(e.getQyxmmc().replaceAll((char) (65311) + "", " "));
                    }
                    if (StringUtils.isNotBlank(e.getZcxmmc())) {
                        e.setZcxmmc(e.getZcxmmc().replace((char) (65311) + "", " "));
                    }
                });
                zcfzb.put("list", zcfzbList);
                NsrxxForm nsrxxForm = gsCwbbVo.getSyxqyzcfzb().getNsrxxForm1();
                if (nsrxxForm != null) {
                    zcfzb.put("zcfzbr", nsrxxForm.getZcfzbr());
                }
                zcfzb.put("ssqq", cwbbDto.getSkssqq());
                zcfzb.put("ssqz", cwbbDto.getSkssqz());
            }
        } else if (CwbbKjzzEnum.QYKJZD == kjzz) {
            templateFile = "cwbb_qykjzd_template" + templateFileTtype + ".xls";
            if (gsCwbbVo.getQykjzdcwbblrbVO() != null
                    && gsCwbbVo.getQykjzdcwbblrbVO().getQykjzdcwbblrbxxGrid() != null
                    && gsCwbbVo.getQykjzdcwbblrbVO().getQykjzdcwbblrbxxGrid().getQykjzdcwbblrbxxGridlb() != null) {
                List<QykjzdcwbblrbxxGridlb> lrbList = gsCwbbVo.getQykjzdcwbblrbVO().getQykjzdcwbblrbxxGrid().getQykjzdcwbblrbxxGridlb();
                lrbList.forEach( e -> {
                    if (StringUtils.isNotBlank(e.getHmc())) {
                        e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                    }
                });
                lrb.put("list", lrbList);
                NsrxxForm nsrxxForm = gsCwbbVo.getQykjzdcwbblrbVO().getNsrxxForm();
                if (nsrxxForm != null) {
                    lrb.put("bsrq", nsrxxForm.getBsrq());
                }
                lrb.put("ssqq", cwbbDto.getSkssqq());
                lrb.put("ssqz", cwbbDto.getSkssqz());
            }
            if (gsCwbbVo.getQykjzdcwbbxjllbVO() != null
                    && gsCwbbVo.getQykjzdcwbbxjllbVO().getQykjzdcwbbxjllbxxGrid() != null
                    && gsCwbbVo.getQykjzdcwbbxjllbVO().getQykjzdcwbbxjllbxxGrid().getQykjzdcwbbxjllbxxGridlb() != null) {
                List<QykjzdcwbbxjllbxxGridlb> xjllbList = gsCwbbVo.getQykjzdcwbbxjllbVO().getQykjzdcwbbxjllbxxGrid().getQykjzdcwbbxjllbxxGridlb();
                xjllbList.forEach( e -> {
                    if (StringUtils.isNotBlank(e.getHmc())) {
                        e.setHmc(e.getHmc().replaceAll((char) (65311) + "", " "));
                    }
                });
                xjllb.put("list", xjllbList);
                NsrxxForm nsrxxForm = gsCwbbVo.getQykjzdcwbbxjllbVO().getNsrxxForm();
                if (nsrxxForm != null) {
                    xjllb.put("bsrq", nsrxxForm.getBsrq());
                }
                xjllb.put("ssqq", cwbbDto.getSkssqq());
                xjllb.put("ssqz", cwbbDto.getSkssqz());
            }
            if (gsCwbbVo.getQykjzdcwbbzcfzbVO() != null
                    && gsCwbbVo.getQykjzdcwbbzcfzbVO().getBdxxGrid() != null
                    && gsCwbbVo.getQykjzdcwbbzcfzbVO().getBdxxGrid().getZcfzbdxxGridlb() != null) {
                List<ZcfzbdxxGridlb> zcfzbList = gsCwbbVo.getQykjzdcwbbzcfzbVO().getBdxxGrid().getZcfzbdxxGridlb();
                zcfzb.put("list", zcfzbList);
                zcfzbList.forEach(e -> {
                    if (e.getQyxmmc() != null) {
                        e.setQyxmmc(e.getQyxmmc().replaceAll((char) (65311) + "", " "));
                    }
                    if (e.getZcxmmc() != null) {
                        e.setZcxmmc(e.getZcxmmc().replaceAll((char) (65311) + "", " "));
                    }
                });
                NsrxxForm nsrxxForm = gsCwbbVo.getQykjzdcwbbzcfzbVO().getNsrxxForm();
                if (nsrxxForm != null) {
                    zcfzb.put("zcfzbr", nsrxxForm.getZcfzbr());
                }
                zcfzb.put("ssqq", cwbbDto.getSkssqq());
                zcfzb.put("ssqz", cwbbDto.getSkssqz());
            }
        } else {
//            throw new JeecgBootException("不支持该会计制度财报导出");
            return exportError(tynsrsbh,"不支持该会计制度财报导出");
        }
        String path = this.getClass().getResource("/").getPath();
        if (StringUtils.isBlank(excelTemplateDir)) {
            excelTemplateDir = path + "templates" + File.separator + "excel";
        }
        String filePath = excelTemplateDir + File.separator + templateFile;
        return this.exportXls(request,
                tynsrsbh + "财务报表",
                filePath,
                data);
    }

    protected ModelAndView exportXls(HttpServletRequest request, String title, String templateUrl, Map<String, Object> data) {
        TemplateExportParams params = new TemplateExportParams(templateUrl,0,1,2);
        //AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new MyJeecgTemplateExcelView());
        mv.addObject(TemplateExcelConstants.PARAMS, params);
        mv.addObject(NormalExcelConstants.FILE_NAME, title);
        mv.addObject(NormalExcelConstants.MAP_LIST, data);
        return mv;
    }

    protected ModelAndView exportError(String tynsrsbh, String errorMsg) {
        // Step.3 AutoPoi 导出Excel
        ExportXlsErrorVo vo = ExportXlsErrorVo.builder().no("1").result("导出失败").errorMsg(errorMsg).build();
        List<ExportXlsErrorVo> dataList = new ArrayList<>();
        dataList.add(vo);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String title = "财报报表";
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, tynsrsbh + "财务报表");
        mv.addObject(NormalExcelConstants.CLASS, ExportXlsErrorVo.class);
        ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
        mv.addObject(NormalExcelConstants.PARAMS,exportParams);
        mv.addObject(NormalExcelConstants.DATA_LIST, dataList);
        return mv;
    }

//    public static void main(String[] args) {
//
//        String s = "？？？？？减：营业成本";
//        for (int i = 0; i < s.length(); i++) {
//            System.out.println(s.charAt(i) - 0);
//        }
//        System.out.println(s.replaceAll((char) (65311) + "", ""));
//    }
}
